home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / delphi1 / lessons.exe / lesson4 / BUG / BUG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-26  |  954 b   |  52 lines

  1. unit Bug;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ListBox1: TListBox;
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure FormCreate(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. const
  29.   NumberOfItems = 4;
  30.  
  31. procedure TForm1.Button1Click(Sender: TObject);
  32. var
  33.    CurrentIndex : integer;
  34. begin
  35.   CurrentIndex := ListBox1.ItemIndex;
  36.   If CurrentIndex < NumberOfItems then
  37.      Inc(CurrentIndex)
  38.   Else CurrentIndex := 0;
  39.   ListBox1.ItemIndex := CurrentIndex;
  40. end;
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. var
  44.  i : integer;
  45. begin
  46.  for i := 1 to NumberOfItems do
  47.    ListBox1.Items.Add( 'Item Number: ' + IntToStr(i));
  48.    ListBox1.ItemIndex := 0;
  49. end;
  50.  
  51. end.
  52.